package com.cheng.admin.rabbitmq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    @Bean
    public DirectExchange delayedOrderCancelExchange() {
        return ExchangeBuilder.directExchange(MqConstants.DELAY_EXCHANGE_ORDER).durable(true).delayed().build();
    }

    @Bean
    public Queue delayedOrderCancelQueue() {
        return new Queue(MqConstants.DELAY_QUEUE_ORDER_CANCEL);
    }

    @Bean
    public Binding delayedOrderCancelBidding(Queue delayedOrderCancelQueue, DirectExchange orderCancelExchange) {
        return BindingBuilder.bind(delayedOrderCancelQueue).to(orderCancelExchange).with(delayedOrderCancelQueue.getName());
    }

    @Bean
    public Queue delayedOrderConfirmQueue() {
        return new Queue(MqConstants.DELAY_QUEUE_ORDER_CONFIRM);
    }

    @Bean
    public Binding delayedOrderConfirmBidding(Queue delayedOrderConfirmQueue, DirectExchange orderCancelExchange) {
        return BindingBuilder.bind(delayedOrderConfirmQueue).to(orderCancelExchange).with(delayedOrderConfirmQueue.getName());
    }
}
